package com.cai.primeton.service;

import com.cai.primeton.entity.PBook;
import com.cai.primeton.repository.BookRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

/**
 * @version 1.0
 * @author：蔡松坡
 * @date：2021/7/6 12 : 32
 * @package：com.cai.primeton.service
 */
@Service
@Transactional
public class BookServiceImpl implements BookService {

    @Autowired
    private BookRepo bookRepo;

    @Override
    public List<PBook> findAllByType(Integer type) {
        List<PBook> allByType = bookRepo.findAllByType(type);
        return allByType;
    }

    @Override
    public void save(PBook pBook) {
        bookRepo.save(pBook);
    }

    @Override
    public PBook findById(Integer id) {
        Optional<PBook> byId = bookRepo.findById(id);
        return byId.get();
    }

    @Override
    public void deleteById(Integer id) {
        bookRepo.deleteById(id);
    }
}
